/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.tesoreria.beans;

import java.util.List;
import javax.faces.model.SelectItem;
import org.cip.esymons.eventos.be.Evento;
import org.cip.esymons.eventos.be.Preevento;
import org.cip.esymons.tesoreria.bc.EventoDelegate;

/**
 *
 * @author Ingrid Capuñay
 */
public class EventoController {

    private EventoDelegate delegado;
    public EventoController() {
        delegado = new EventoDelegate();
    }

    public Evento buscarPorCodigo(Integer id){
        try{
            return delegado.find(id);
        }catch(Exception ex){
            return null;
        }
    }

    public SelectItem[] getEventoItem() {
        try {
            List<Evento> lc = delegado.listarEventoCurso();
            SelectItem[] select = new SelectItem[lc.size()];
            int i = 0;
            for (Evento ev : lc) {
                System.out.println("evento: " + ev.getPreevento());
                SelectItem item = new SelectItem(ev, ev.getPreevento().getPreNombre());
                select[i++] = item;
            }

            return select;
            
        } catch (Exception ex) {
            SelectItem[] select = new SelectItem[1];
            SelectItem item = new SelectItem(null,"No existen Eventos");
            select[0] = item;
            return select;
        }
    }

    //lizardo estuvo aqui
    public SelectItem[] getEventoItem2() {
        try {
            List<Preevento> lc = delegado.listarEventoCurso2();
            SelectItem[] select = new SelectItem[lc.size()];
            int i = 0;
            for (Preevento ev : lc) {
                System.out.println("evento: " + ev.getPreNombre());
                SelectItem item = new SelectItem(ev.getPreCodigo(), ev.getPreNombre());
                select[i++] = item;
            }
            return select;

        } catch (Exception ex) {
            SelectItem[] select = new SelectItem[1];
            SelectItem item = new SelectItem(null,"No existen Eventos");
            select[0] = item;
            return select;
        }
    }

}
